package com.newy.web.sys;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.newy.core.BaseController;
import com.newy.core.util.Converter;
import com.newy.core.util.Page;
import com.newy.domain.sys.Department;
import com.newy.domain.sys.LoginLog;
import com.newy.domain.sys.User;
import com.newy.service.sys.LogService;
import com.newy.service.sys.UserService;

/**
 * 日志管理控制器类
 * @author LinZongxue
 * @Create_date 2011-12-23
 */
@Controller
@RequestMapping("sys/log")
public class LogController extends BaseController {
	@Resource private LogService logSvc;
	@Resource private UserService userSvc;
	
	/**
	 * 查询登陆日志
	 */
	@RequestMapping("queryLoginLogs")
	public @ResponseBody Page queryLoginLog(Page page, LoginLog log){
		logSvc.findLoginLogsByPage(page, log);
		return new Converter()
			.addField("loginName", "userId", User.class, "loginName")
			.addField("userName", "userId", User.class, "name")
			.addField("departName", new Converter.Convert<LoginLog>() {
				public Object to(LoginLog src){
					Department org = userSvc.getDepartOfUser(src.getUserId());
					return org != null ? org.getName() : "";
				}
			}).toListOfMap(page);
	}
	
	/**
	 * 删除登陆日志
	 * @param ids
	 */
	@RequestMapping("deleteLoginLogs")
	public @ResponseBody void deleteLoginLogs(Long[] ids){
		logSvc.deleteLoginLogs(ids);
	}
}
